package exception_homework;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
/**
 * PWDemo2简要记事本按行写
 */
public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos = new FileOutputStream("pw4.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos,StandardCharsets.UTF_8);
        BufferedWriter bw  = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入文字,并单独输入exit时自动退出:");
        while (true){
            String line = scanner.nextLine();
            if ("exit".equals(line)){
                System.out.println("输出完成!");;
                break;
            }
            pw.println(line);

        }
        pw.close();
    }
}
